<template>
  <div class="reset-main">
    <el-form ref="newruleForm" class="reset-main-form" :model="newruleForm" :rules="rules">
      <div class="total-text">子库名称<span style="color:red;margin-right:3px;">*</span></div>
      <el-form-item prop="name" class="reset-main-form-one">
        <el-input v-model="newruleForm.name" maxlength="20" show-word-limit />
      </el-form-item>
      <div class="total-text">子库描述 <span style="font-size:11px;margin-left:5px;opacity:0.7;">非必填</span></div>
      <el-form-item>
        <el-input v-model="newruleForm.region" maxlength="100" rows="6" show-word-limit type="textarea" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
// 这里就是调用可用模板列表 获取数据库新增
import { createDatabase } from '@/api/table'
export default {
  name: 'CreatChild',
  data() {
    return {
      // 这里就是完善信息的内容
      newruleForm: {
        name: '',
        region: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入子库名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    closeChild() {
      console.log('close')
      this.$refs.newruleForm.resetFields()
      this.newruleForm = {}
    },
    // 创建数据库最终提交数据
    async  totalSubmit() {
      // 校验
      try { await this.$refs.newruleForm.validate() } catch (e) {
        return this.$message.error('请输入子库名称')
      }
      // 拿数据
      console.log('newTemplate', this.newTemplate)
      // database_id有值创建子库，反之创建总库
      const database_id = this.$store.state.user.getSelect.id
      // const template_id = this.$store.getters.template_id
      const user_template_id = this.$store.state.user.getSelect.template_id
      var nerRes = {
        parent_id: database_id,
        origin_template_id: user_template_id,
        database_name: this.newruleForm.name,
        database_introduction: this.newruleForm.region || '',
        create_template_data: null
      }
      console.log(nerRes)
      const res = await createDatabase(nerRes)
      console.log('新增子目录', res)
      if (res.data.code === 0) {
        this.$message.error(res.data.msg)
      } else if (res.data.code === 1) {
        this.$message.success(res.data.msg)
      } else {
        this.$message.error(res.data.msg)
      }
    }
  }

}
</script>
<style>
/* 修改el-input内部结构 */
.reset-main-form-one  .el-input .el-input__count{
      right: -50px !important;
      position: relative;
}
.reset-main-form .el-textarea .el-input__count{
      right: -50px !important;
}

</style>

<style lang="scss" scoped>
.reset-main {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  .reset-main-form {
    width: 400px;
    padding: 20px 70px;
    .total-text{
      height: 40px;
      line-height: 40px;
    }
  }
}
</style>
